package com.thinkgem.jeesite.modules.feedback.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.building.service.RoomService;
import com.thinkgem.jeesite.modules.feedback.dao.FeedbackDao;
import com.thinkgem.jeesite.modules.feedback.entity.Feedback;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

@Service
@Transactional(readOnly=true)
public class FeedbackService extends CrudService<FeedbackDao, Feedback>{
	@Autowired
	FeedbackDao feedbackDao;
	@Autowired
	RoomService roomservice;
	
	/**
	 * 自己管辖下的房间的反馈
	 * */
	public Page<Feedback> findMyFeedbackList(Page<Feedback> page,Feedback feedback){
		feedback.setPage(page);
		feedback.setId(UserUtils.getUser().getId());
		page.setList(feedbackDao.findMyFeedbackList(feedback));
		return page;
	}
	/**
	 * 找到房主的反馈
	 * */
	public Page<Feedback> findOwnerFeedback(Page<Feedback>page,Feedback feedback){
		feedback.setPage(page);
		feedback.setRoom((roomservice.findRoomByOwnerId(UserUtils.getUser().getId())));
		page.setList(feedbackDao.findOwnerFeedback(feedback));
		return page;
	}
	@Transactional(readOnly = false)
	public void insertFeedback(Feedback feedback){
		feedbackDao.insertFeedback(feedback);
	}
	@Transactional(readOnly = false)
	public void updateState(Feedback feedback){
		feedbackDao.updateState(feedback);
	}
	
	
}
